package cn.xxi.ai.workflow.core.node.end;

import cn.xxi.ai.workflow.core.node.NormalNode;
import cn.xxi.ai.workflow.core.node.Position;
import cn.xxi.ai.workflow.core.node.Style;
import cn.xxi.ai.workflow.state.State;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * End node
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EndNode extends NormalNode<EndData> {

    private String id;
    private EndData data;
    private Position position;
    private Style style;

    @Override
    public Map<String, Object> process(State state) {
        return Collections.emptyMap();
    }

    public Map<String, Object> outputs(State state) {
        Map<String, Object> result = new HashMap<>();
        if (data.getOutputs() != null) {
            for (EndData.Output output : data.getOutputs()) {
                result.put(output.getField(), state.any(output.getVariable()));
            }
        }
        return result;
    }
}